/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("Ads_AbnormalType",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using DGZImp.AdsProject.DomainModels;
using DGZImp.AdsProject.IServices;
using DGZImp.Core.Utilities.Response;

namespace DGZImp.AdsProject.Controllers
{
    public partial class Ads_AbnormalTypeController
    {
        private readonly IAds_AbnormalTypeService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public Ads_AbnormalTypeController(
            IAds_AbnormalTypeService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }

        /// <summary>
        /// 获取异常类型列表
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        [HttpGet("GetTree")]
        public async Task<ApiResponse<List<AbnormalTypeDto>>> GetTree(bool isFilter)
        {
            var res = await _service.GetTree(isFilter);
            return ApiRes.Success(res);
        }

        /// <summary>
        /// 获取异常类型详情
        /// </summary>
        /// <param name="AbnormalTypeId"></param>
        /// <returns></returns>
        [HttpGet("GetDetail")]
        public async Task<ApiResponse<AbnormalTypeDetailDto>> GetDetail(long AbnormalTypeId)
        {
            var res = await _service.GetDetail(AbnormalTypeId);
            return ApiRes.Success(res);
        }

        /// <summary>
        /// 添加或更新异常类型
        /// </summary>
        /// <param name="Dto"></param>
        /// <returns></returns>
        [HttpPost("AddOrUpdate")]
        public async Task<ApiResponse<long>> AddOrUpdate([FromBody] AbnormalTypeDetailDto Dto)
        {
            var res = await _service.AddOrUpdate(Dto);
            return ApiRes.Success(res);
        }

        /// <summary>
        /// 通过部门获取用户
        /// </summary>
        /// <param name="deptId"></param>
        /// <returns></returns>
        [HttpGet("GetUsersByDept")]
        public async Task<ApiResponse<List<keyValueDto>>> GetUsersByDept(long deptId)
        {
            var res = await _service.GetUsersByDept(deptId);
            return ApiRes.Success(res);
        }
    }
}
